package com.xhs.main.controller.xsb;

import com.alibaba.fastjson.JSONObject;
import com.xhs.main.entity.result.LayuiResponseResult;
import com.xhs.main.entity.xsb.Invoice;
import com.xhs.main.service.xsb.impl.XsbInvoiceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hjr
 * @create 2020-10-20-下午 5:44
 */

@RestController
public class InvoiceController {

    @Autowired
    XsbInvoiceServiceImpl xsbInvoiceService;

    @RequestMapping("/addInv")
    public void add(Invoice invoice){
        System.out.println(invoice);
        xsbInvoiceService.addInvocie(invoice);
    }


    @RequestMapping("/getAllInvoice")
    public LayuiResponseResult showAllPlan(){
        List<Invoice> allInvoice = xsbInvoiceService.getAllInvoice();
        LayuiResponseResult result = new LayuiResponseResult();
        result.setCode(0);
        result.setMsg("成功");
        result.setCount(allInvoice.size());
        result.setData(allInvoice);

        return  result;
    }

    @RequestMapping("/getInv")
    public LayuiResponseResult showAllInvoiceByVague(@RequestParam("searchParams") String searchParams){
        System.out.println(searchParams);

        Invoice invoice = JSONObject.parseObject(searchParams, Invoice.class);
        System.out.println(invoice);
        List<Invoice> allInvoiceByVague = xsbInvoiceService.getAllInvoiceByVague(invoice);
        System.out.println(allInvoiceByVague);
        return null;
    }

    @RequestMapping("/updateInv")
    public LayuiResponseResult update(@RequestParam("searchParams") String searchParams){

        System.out.println(searchParams);
        Invoice invoice = JSONObject.parseObject(searchParams, Invoice.class);

        List<Invoice> invoices = xsbInvoiceService.updateInvoice(invoice);
        LayuiResponseResult result = new LayuiResponseResult();
        result.setCode(0);
        result.setMsg("成功");
        result.setCount(invoices.size());
        result.setData(invoices);

        return result;
    }
}
